﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Business;

namespace H2.NET.Web.Pages
{
    public partial class SAPCode : TaskControl
    {
        public string FORM
        {
            get
            {
                return (Parent as TabMaterial).Status.FORM;
            }
        }

        public string Category
        {
            get
            {
                return (Parent as TabMaterial).Status.Category;
            }
        }

        #region 属性 Public
        private bool IsUsed
        {
            get
            {
                string s = (Parent as TabMaterial).Status.SAP_Code;
                return !string.IsNullOrEmpty(s) && (s == "C" || s == "S");
            }
        }
        #endregion

        #region 事件 页面加载
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #endregion

        #region 方法 InitControls(初始化)
        public void InitControls(mdc_Material mt)
        {
            Visible = IsUsed;
            if (!IsUsed)
            {
                return;
            }

            Distribute(mt);
            SetEnable(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit, SAP_SAP_Code, SAP_Description);
            SetForeColor(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit ? Color.Blue : Color.Black, SAP_SAP_Code_L, SAP_Description_L);
            SetVisible(true, SAP_SAP_Code_L);
            if(TaskAPI.Process=="Raw Code Extend Application"||TaskAPI.Process=="Raw Code Change Application"||TaskAPI.Process=="Raw Code Pack Size Change"||TaskAPI.Process=="Sefi Code Application"||TaskAPI.Process=="P-Plant Extend Application"||TaskAPI.Process=="Formula Change Application")
            {
                SetVisible(true, SAP_Description, SAP_Description_L);
            }
            if (Category == "PACK" && TaskAPI.Process == "P-Plant Extend Application")
            {
                SetVisible(false, SAP_Description, SAP_Description_L);
            }
            
        }
        #endregion

        #region 方法 Distribute,Collect(分发, 收集值)
        public void Distribute(mdc_Material mt)
        {
            //如果当前 Tabs 是隐藏的情况，退出
            if (!IsUsed)
            {
                return;
            }

            SAP_SAP_Code.Text = mt.SAP_Code;
            SAP_Description.Text = mt.SAP_Description;
        }

        public void Collect(ref mdc_Material mt)
        {
            //如果当前 Tabs 是隐藏的情况，退出
            if (!IsUsed)
            {
                return;
            }

            mt.SAP_Code = SAP_SAP_Code.Text;
            mt.SAP_Description = SAP_Description.Text;
        }
        #endregion

        #region 方法 DataValidation(数据验证)
        public List<string> DataValidation(mdc_Material mt, string Sheet)
        {
            List<Regular> regs = new List<Regular>();

            //如果当前 Tabs 是隐藏的情况，退出
            if (!IsUsed)
            {
                if(TaskAPI.Process == "PKG Sefi Code BOM Application" && !(Page as PMDC).Code_Selected.Checked && (Page as PMDC).Actions.SelectedValue == "Revision")
                {
                    return new List<string>();
                }
                if (TaskAPI.Process == "PKG Fini Code BOM Application" && (Page as PMDC).Code_Selected.Checked && (Page as PMDC).Actions.SelectedValue == "Revision")
                {
                    string s = (Page as PMDC).TabMaterial1.SAPCode1.SAP_SAP_Code.Text + (Page as PMDC).TabMaterial2.SAPCode1.SAP_SAP_Code.Text;
                    if (!string.IsNullOrEmpty(s))
                    {
                        return new List<string>();
                    }
                }
                //if (TaskAPI.Process == "TW Raw Code Application" && (Page as PMDC).Code_Selected.Checked)
                //{
                //    if ((Page as PMDC).TabMaterial1.SAPCode1.SAP_SAP_Code.Visible)
                //    {
                //        akzo_RegularCheck(ref regs, RegularExp.NotEmpty, (Page as PMDC).TabMaterial1.SAPCode1.SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");
                //    }
                //}
                //if (TaskAPI.Process == "TW Raw Code Application" && (Page as PMDC).BOM_Selected.Checked)
                //{
                //    if ((Page as PMDC).TabMaterial1.SAPCode1.SAP_SAP_Code.Visible)
                //    {
                //        akzo_RegularCheck(ref regs, RegularExp.NotEmpty, (Page as PMDC).TabMaterial2.SAPCode1.SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");
                //    }
                //}
            }

            if (this.TaskAPI.Process == "HK ADVE Code Application")
            {
                if ((Page as PMDC).rd_HK_ADVE_Biz_Type.SelectedValue == "0" && (Parent as TabMaterial).Status.FORM == "FORM-065-1" && this.SAP_SAP_Code.Visible && (Page as PMDC).Actions.SelectedValue != "Creation")
                {
                    akzo_RegularCheck(ref regs, RegularExp.NotEmpty, SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");
                }

                if ((Page as PMDC).rd_HK_ADVE_Biz_Type.SelectedValue == "1" && (Parent as TabMaterial).Status.FORM == "FORM-065-2" && this.SAP_SAP_Code.Visible && (Page as PMDC).Actions.SelectedValue != "Creation")
                {
                    akzo_RegularCheck(ref regs, RegularExp.NotEmpty, SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");
                }

                return Validation(regs);
            }
            if (this.TaskAPI.Process == "TW Raw Code Application")
            {
                if ((Page as PMDC).rd_Raw_Code.SelectedValue == "0" && (Parent as TabMaterial).Status.FORM == "FORM-T003" && this.SAP_SAP_Code.Visible)
                {
                    akzo_RegularCheck(ref regs, RegularExp.NotEmpty, SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");
                }

                if ((Page as PMDC).rd_Raw_Code.SelectedValue == "1" && (Parent as TabMaterial).Status.FORM == "FORM-T018" && this.SAP_SAP_Code.Visible)
                {
                    akzo_RegularCheck(ref regs, RegularExp.NotEmpty, SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");
                }

                return Validation(regs);
            }
            if (this.TaskAPI.Process == "D-Plant Extend Application")
            {
                akzo_RegularCheck(ref regs, RegularExp.NotEmpty, SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");
            }
            if (this.TaskAPI.Process == "Raw Code Extend Application" || this.TaskAPI.Process == "Raw Code Change Application" || this.TaskAPI.Process == "Raw Code Pack Size Change" || this.TaskAPI.Process == "Sefi Code Application" || this.TaskAPI.Process == "P-Plant Extend Application" || this.TaskAPI.Process == "Formula Change Application")
            {
                akzo_RegularCheck(ref regs, RegularExp.NotEmpty, SAP_Description_L, mt.SAP_Description, Sheet + "Description 必填");
            }

            //if (TaskAPI.Process == "P-Plant Extend Application" && FORM == "FORM-005" && !(Parent as PMDC).SefiCode_Selected.Checked)
            //{
            //    return new List<string>();
            //}

            //if (TaskAPI.Process == "P-Plant Extend Application" && FORM == "FORM-002" && !(Parent as PMDC).PackCode_Selected.Checked)
            //{
            //    return new List<string>();
            //}
            
            //List<Regular> regs = new List<Regular>();
            if (this.SAP_SAP_Code.Visible && (Page as PMDC).Actions.SelectedValue != "Creation")
            {
                akzo_RegularCheck(ref regs, RegularExp.NotEmpty, SAP_SAP_Code_L, mt.SAP_Code, Sheet + "SAP Code 必填");

            }
            
            return Validation(regs);
        }
        #endregion
    }
}
